package com.zbbt.sportslottery.util;


import java.security.MessageDigest;

import com.zbbt.sportslottery.app.Constant;

public class Md5 {
	private static Md5 md5=new Md5();
	public static Md5 getMD5(){
		return md5;
	}
	
	public static String getMD5(String password){
		String result = null;
		char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};//用来将字节转换成 16 进制表示的字符
		if(password!=null)
		{
			try {
				MessageDigest md = MessageDigest.getInstance("MD5");
				byte[] source=password.getBytes("utf-8");
				md.update(source);
				byte[] tmp=md.digest();
				char[] str=new char[32];
				for(int i=0,j=0;i<16;i++)
				{
					byte b=tmp[i];
					str[j++]=hexDigits[b>>>4 & 0xf];
					str[j++] = hexDigits[b&0xf];
				}
				result = new String(str);
				
			} catch (Exception e) {
				// TODO: handle exception
				e.printStackTrace();
			}
		}
		return result;
	}
	
	public static void main(String args[])  throws Exception{
		String s=Md5.getMD5(Constant.SECURITY_KEY);
		System.out.println(s);
	}

}









